var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    defenarr: [], //每提得分情况
    count: 0, //总分
    current: 0, //第几题
    scoreArr: [],
    progrp: '50%' //进度条
  },
  response: function(e) {
    console.log(e)
    var that = this;
    var sum = 0
    var defenarr = that.data.defenarr
    var score = e.currentTarget.dataset.score
    var dex = e.currentTarget.dataset.dex
    var newArr = that.data.row
    var tixing = that.data.tixing
    var arr = []
    defenarr.push(score)
    defenarr.forEach(function(e) {
      sum += e * 1;
    });
    var current = ++that.data.current
    that.setData({
      current: current,
      defenarr: defenarr,
      count: sum,
      progrp: '100%'
    })
    if (current == tixing.length) {
      newArr.forEach(function(value, index) {
        if (sum == value.start) {
          that.setData({
            jianyi: value.suggest,
            arr: value
          })
        }
      })
    }
  },
  backbtn() {
    var t = this,
      dfs = t.data.defenarr,
      n = t.data.count;
    n -= dfs[dfs.length - 1];
    dfs.pop();
    t.setData({
      current: --t.data.current,
      count: n,
      defenarr: dfs,
      progrp: '100%'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var id = options.id
    var title = options.title
    wx.setNavigationBarTitle({
      title: title
    })
    that.setData({
      id: id
    })
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.getYuzhen()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  getYuzhen() {
    var that = this
    var id = that.data.id
    app.util.request({
      'url': 'entry/wxapp/Yuzhen.onedata',
      data: {
        id: id
      },
      success: function(res) {
        console.log(res)
        that.setData({
          tixing: res.data.spec,
          row: res.data.num
        })
      }
    })
  }
})